package com.party.core.service.commune.impl;

import com.party.common.paging.Page;
import com.party.core.dao.read.commune.CUserIntegralReadDao;
import com.party.core.dao.write.commune.CUserIntegralWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.commune.CMemberIntegralBalanceLog;
import com.party.core.model.commune.CUserIntegral;
import com.party.core.model.commune.CUserIntegralMobileOutput;
import com.party.core.model.commune.CUserIntegralOutput;
import com.party.core.service.commune.ICUserIntegralService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @program: party
 * @description: 用户积分服务实现
 * @author: Hua Qunhao
 * @create: 2019-08-12 14:31
 **/
@Service
public class CUserIntegralService implements ICUserIntegralService {

    @Autowired
    private CUserIntegralReadDao cUserIntegralReadDao;

    @Autowired
    private CUserIntegralWriteDao cUserIntegralWriteDao;


    @Override
    public String insert(CUserIntegral cUserIntegral) {
        BaseModel.preInsert(cUserIntegral);
        boolean result = cUserIntegralWriteDao.insert(cUserIntegral);
        if (result) {
            return cUserIntegral.getId();
        }
        return null;
    }

    @Override
    public boolean update(CUserIntegral cUserIntegral) {
        cUserIntegral.setUpdateDate(new Date());
        return cUserIntegralWriteDao.update(cUserIntegral);
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        return cUserIntegralWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        return false;
    }

    @Override
    public CUserIntegral get(String id) {
        return cUserIntegralReadDao.get(id);
    }

    @Override
    public List<CUserIntegral> listPage(CUserIntegral cUserIntegral, Page page) {
        return cUserIntegralReadDao.listPage(cUserIntegral, page);
    }

    @Override
    public List<CUserIntegral> list(CUserIntegral cUserIntegral) {
        return cUserIntegralReadDao.listPage(cUserIntegral, null);
    }

    @Override
    public List<CUserIntegral> batchList(Set<String> ids, CUserIntegral cUserIntegral, Page page) {
        return null;
    }

    @Override
    public List<CUserIntegralOutput> queryUserIntegralList(Map<String, Object> params, Page page) {
        return cUserIntegralReadDao.queryUserIntegralList(params, page);
    }

    @Override
    public Double getUserItemFractionSum(CUserIntegral cUserIntegral) {
        return cUserIntegralReadDao.getUserItemFractionSum(cUserIntegral);
    }

    /**
     * @Description: 通过机构id 获取积分排行榜
     * @Param:partnerId
     * @return:List<CUserIntegralMobileOutput>
     * @Author: Hua Qunhao
     * @Date: 2019/8/30
     */
    @Override
    public List<CUserIntegralMobileOutput> queryUserIntegralMobileList(Map<String, Object> params, Page page) {
        return cUserIntegralReadDao.queryUserIntegralMobileList(params, page);
    }

    @Override
    public List<CUserIntegralMobileOutput> queryUserIntegralWebList(Map<String, Object> params, Page page) {
        return cUserIntegralReadDao.queryUserIntegralWebList(params,page);
    }

    /**
     * @Description: 通过机构id和机构用户关系表id  获取当前用户在该机构下的积分排行
     * @Param:partnerId,pmId
     * @return:CUserIntegralMobileOutput
     * @Author: Hua Qunhao
     * @Date: 2019/8/30
     */
    @Override
    public CUserIntegralMobileOutput queryUserIntegralMobile(Map<String,Object> params) {
        return cUserIntegralReadDao.queryUserIntegralMobile(params);
    }

    @Override
    public List<CUserIntegralMobileOutput> queryIntegralInfluenceRankingList(Map<String,Object> params, Page page) {
        return cUserIntegralReadDao.queryIntegralInfluenceRankingList(params, page);
    }

    @Override
    public CUserIntegralMobileOutput queryIntegralInfluenceRanking(Map<String,Object> params) {
        return cUserIntegralReadDao.queryIntegralInfluenceRanking(params);
    }

    @Override
    public List<CUserIntegralMobileOutput> getRecommendPersonList(Map<String, Object> params, Page page) {
        return cUserIntegralReadDao.getRecommendPersonList(params,page);
    }

    @Override
    public Double getRecommendItemFractionSum(String parentId, String typeId) {
        return cUserIntegralReadDao.getRecommendItemFractionSum(parentId,typeId);
    }

    @Override
    public List<CUserIntegralMobileOutput> queryIntegralInfluenceRankingListWithWeb(Map<String, Object> params, Page page) {
        return cUserIntegralReadDao.queryIntegralInfluenceRankingListWithWeb(params,page);
    }

    @Override
    public Double getUserItemFractionSumWithParams(Map<String, Object> params) {
        return cUserIntegralReadDao.getUserItemFractionSumWithParams(params);
    }

    @Override
    public Double getRecommendItemFractionSumWithParam(Map<String, Object> params) {
        return cUserIntegralReadDao.getRecommendItemFractionSumWithParam(params);
    }

    @Override
    public List<String> groupByPmIdList() {
        return cUserIntegralReadDao.groupByPmIdList();
    }

    @Override
    public void batchUpdatePartnerAndMember(String partnerId, String memberId, String pmId) {
        cUserIntegralWriteDao.batchUpdatePartnerAndMember(partnerId, memberId, pmId);
    }

    @Override
    public Double getMemberGroupScoreByTypeId(List<String> memberGroupIds,Map<String, Object> params) {
        return cUserIntegralReadDao.getMemberGroupScoreByTypeId(memberGroupIds,params);
    }

    @Override
    public List<CMemberIntegralBalanceLog> queryUserIntegralAll(Map<String,Object> params) {
        return cUserIntegralReadDao.queryUserIntegralAll( params);
    }
}
